07. Exercise: Scanner

Scanner Exercise

Task Description:

This exercise will show you how to receive input from the console using the Scanner class

Task List:

Task Feedback:

Nice work!

Solution

ND079 C1 L4 A07 Scanner Solutions

import java.util.Scanner;

public class UserInputTester {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        try {
            System.out.println("Enter a String");
            String userInput = scanner.nextLine();
            System.out.println("User Input: " + userInput);

        } catch (Exception ex) {
            ex.getLocalizedMessage();
        } finally {
            scanner.close();
        }

    }
}